package org.medicalinstrument.impl;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.medicalinstrument.bean.RentOrderMaster;
import org.medicalinstrument.dao.RentOrderDao;
import org.medicalinstrument.database.DataSourceUtils;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public class RentOrderDaoImpl implements RentOrderDao {
    //获取数据连接池
    QueryRunner qr = new QueryRunner(DataSourceUtils.getDataSource());
    @Override
    public Boolean add(Connection conn, RentOrderMaster order) throws Exception {
        String sql = "insert into rentordermaster values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        int update = qr.update(conn,sql, order.getRentOrderId(), order.getAccountNo(),
                order.getOrderTime(), order.getRentTime(), order.getRealRentTime(),
                order.getRentDays(), order.getRealRentDays(), order.getConsigeeAddr(),
                order.getGetOrConsigee(), order.getRentTotalMoney(), order.getRalRentTotalMoney(),
                order.getRealRentMoney(), order.getRentMoneyTime(), order.getOrderState());
        return update > 0;
    }

    @Override
    public Boolean delete(String rentOrderId) throws Exception {
        String sql = "delete from rentordermaster where rentOrderId = ? ";
        int update = qr.update(sql, rentOrderId);
        return update > 0;
    }

    @Override
    public List<RentOrderMaster> getAll() throws SQLException {
        String sql = "select * from rentordermaster";
        List<RentOrderMaster> rentOrderMasters = qr.query(sql, new BeanListHandler<RentOrderMaster>(RentOrderMaster.class));
        return rentOrderMasters;
    }


}
